package com.corner.presenter.imp;

import com.corner.model.cornerservice.domain.User;
import com.corner.model.cornerservice.helper.UserHelper;
import com.corner.presenter.ISetPasswordPresenter;
import com.corner.presenter.base.BasePresenter;
import com.corner.ui.view.ISetPasswordView;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;

/**
 * Created by Administrator on 2015/9/17.
 */
public class SetPasswordPresenter extends BasePresenter<ISetPasswordView> implements ISetPasswordPresenter{
    @Override
    public void register(String phoneNum, String password) {
        view.showLoading(true);
        UserHelper.register(phoneNum,password).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<User>() {
            @Override
            public void call(User user) {
                if (view != null) {
                    view.registerSucess();
                    view.showLoading(false);
                }
            }
        }, new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                if (view != null) {
                    view.showError(throwable.getMessage());
                    view.showLoading(false);
                }
            }
        });
    }
}
